#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll l,r;
ll b1[105],b2[105];
ll solve(ll l,ll r){
    if(l==r){
        return l;
    }
    ll lel=0,ril=0;
    memset(b1,0,sizeof(b1));
    memset(b2,0,sizeof(b2));
    ll x=l,res=0;
    while(x){
        b1[++lel]=x%2;
        x/=2;
    }
    x=r;
    while(x){
        b2[++ril]=x%2;
        x/=2;
    }
    if(lel!=ril){
        return (1ll<<ril)-1;
    }
    for(ll i=ril;i>0;i--){
        if(b1[i]==b2[i]){
            res+=b1[i]*(1ll<<(i-1));
        }
        else{
            res+=(1ll<<i)-1;
            return res;
        }
    }
}
int main(void){
    ll T;
    scanf("%lld",&T);
    while(T--){
        scanf("%lld%lld",&l,&r);
        printf("%lld\n",solve(l,r));
    }
    return 0;
}